package cn.good.biz.controller;

import cn.good.biz.service.GDDoctorService;
import cn.good.dto.Dto;
import cn.good.dto.DtoUtil;
import cn.good.pojo.Comment;
import cn.good.pojo.Doctor;
import cn.good.vo.DoctorInfoVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/doc/doctor")
@RestController
public class DoctorController {

    @Resource
    private GDDoctorService gdDoctorService;

    /**
     * 查询医生详细信息
     * @param id
     * @return
     */
    @ApiOperation(value="查询医生详细信息",httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class,notes="查询医生详细信息")
    @RequestMapping("/{id}")
    public Dto selectDoctorInfo(@PathVariable("id") Long id){

        DoctorInfoVO doctorInfoVO = null;

        try {
            doctorInfoVO = gdDoctorService.searchDoctorInfo(id);
            return DtoUtil.returnDataSuccess(doctorInfoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","10007");
        }
    }

    @ApiOperation(value="关注医生",httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class,notes="关注医生")
    @RequestMapping("/attention")
    public Dto attention(Long userId,Long doctorId){

        try {
            gdDoctorService.attentionDoctor(userId,doctorId);
            return DtoUtil.returnSuccess("关注成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("关注失败","10008");

        }
    }
    @ApiOperation(value="取关医生",httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class,notes="取关医生")
    @RequestMapping("/cancel")
    public Dto attentionCancel(Long userId,Long doctorId){

        try {
            gdDoctorService.cancelDoctor(userId,doctorId);
            return DtoUtil.returnSuccess("取关成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("取关失败","10008");
        }
    }
    @ApiOperation(value="查询关注医生列表",httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class,notes="查询关注医生列表")
    @RequestMapping("/doctorList")
    public Dto searchDoctorList(Long userId){

        try {
          List<Doctor> list =  gdDoctorService.selectDoctorListByUserId(userId);
            return DtoUtil.returnDataSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","10008");

        }
    }
    @ApiOperation(value="查询医生评论列表",httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class,notes="查询医生评论列表")
    @RequestMapping("/commonList")
    public Dto searchCommonList(Long doctorId){

        try {
            List<Comment> list = gdDoctorService.selectCommonListByUesrDoctorId(doctorId);
            return  DtoUtil.returnDataSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","10008");

        }
    }
}
